package com.logger;

import com.logger.handlers.AHandler;

/**
 * 负责捕捉日志
 * <p>
 * Created by chenxunlin01 on 2016/1/13.
 */

public abstract class Logger {

    //环境配置
    public static Config evnConfig = new Config();
    //所有logger配置
    public static LoggerConfig config = new LoggerConfig();

    public static Logger getLogger(Class<?> clazz) {
        return getLogger(clazz.getName());
    }

    public static Logger getLogger(String tag) {
        return LoggerFactory.getLogger(tag);
    }

    public void verbose(Object msg) {
        log(Level.VERBOSE, msg);
    }

    public void verbose(Object msg, Throwable t) {
        log(Level.VERBOSE, msg, t);
    }

    public void debug(Object msg) {
        log(Level.DEBUG, msg);
    }

    public void debug(Object msg, Throwable t) {
        log(Level.DEBUG, msg, t);
    }

    public void info(Object msg) {
        log(Level.INFO, msg);
    }

    public void info(Object msg, Throwable t) {
        log(Level.INFO, msg, t);
    }

    public void warn(Object msg) {
        log(Level.WARN, msg);
    }

    public void warn(Object msg, Throwable t) {
        log(Level.WARN, msg, t);
    }


    public void error(Object msg) {
        log(Level.ERROR, msg);
    }

    public void error(Object msg, Throwable t) {
        log(Level.ERROR, msg, t);
    }

    public LoggerBuilder append() {
        return new LoggerBuilder(this);
    }

    public LoggerBuilder append(Object msg) {
        return new LoggerBuilder(this, msg);
    }

    public LoggerBuilder buffer(Object... msgs) {
        LoggerBuilder buf = new LoggerBuilder(this);
        for (Object msg : msgs) {
            buf.append(msg);
        }
        return buf;
    }

    public LoggerBuilder format(String format, Object... msgs) {
        return new LoggerBuilder(this).format(format, msgs);
    }

    public void log(Level level, Object message) {
        log(level, message,null);
    }

    public abstract void log(Level level, Object message, Throwable t);

    public abstract void addHandler(AHandler handler);

    public abstract AHandler removeHandler(AHandler handler);
}
